
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/20/2011 13:43:53
-- Generated from EDMX file: D:\Projetos\InWare.InNutri\InWare.InNutri\Core\InWare.InNutri.Data\InNutriModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [InNutri];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Paciente'
CREATE TABLE [dbo].[Paciente] (
    [IdPaciente] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(100)  NOT NULL,
    [DataDeNascimento] datetime  NOT NULL,
    [Naturalidade] nvarchar(50)  NULL,
    [Foto] varbinary(max)  NULL,
    [EstadoCivil_IdEstadoCivil] int  NOT NULL,
    [GrupoEspecifico_IdGrupoEspecifico] int  NULL,
    [Etnia_IdEtnia] int  NULL,
    [Sexo_IdSexo] int  NOT NULL
);
GO

-- Creating table 'EstadoCivil'
CREATE TABLE [dbo].[EstadoCivil] (
    [IdEstadoCivil] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'GrupoEspecifico'
CREATE TABLE [dbo].[GrupoEspecifico] (
    [IdGrupoEspecifico] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Etnia'
CREATE TABLE [dbo].[Etnia] (
    [IdEtnia] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Endereco'
CREATE TABLE [dbo].[Endereco] (
    [IdEndereco] int IDENTITY(1,1) NOT NULL,
    [CEP] nvarchar(10)  NOT NULL,
    [Logradouro] nvarchar(200)  NOT NULL,
    [Numero] int  NOT NULL,
    [Complemento] nvarchar(50)  NOT NULL,
    [Bairro] nvarchar(50)  NOT NULL,
    [Telefone] nvarchar(20)  NULL,
    [Celular] nvarchar(20)  NULL,
    [Email] nvarchar(50)  NULL,
    [Cidade_IdCidade] int  NOT NULL,
    [Tipo_IdTipoEndereco] int  NOT NULL,
    [Paciente_IdPaciente] int  NOT NULL
);
GO

-- Creating table 'Cidade'
CREATE TABLE [dbo].[Cidade] (
    [IdCidade] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(50)  NOT NULL,
    [Estado_IdEstado] int  NOT NULL
);
GO

-- Creating table 'Estado'
CREATE TABLE [dbo].[Estado] (
    [IdEstado] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(50)  NOT NULL,
    [Pais_IdPais] int  NOT NULL
);
GO

-- Creating table 'Pais'
CREATE TABLE [dbo].[Pais] (
    [IdPais] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'TipoEndereco'
CREATE TABLE [dbo].[TipoEndereco] (
    [IdTipoEndereco] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Alimento'
CREATE TABLE [dbo].[Alimento] (
    [IdAlimento] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(50)  NOT NULL,
    [Imagem] varbinary(max)  NULL,
    [Porcao] decimal(9,3)  NOT NULL,
    [CaloriaPorcao] decimal(9,3)  NOT NULL,
    [Referencia_IdReferenciaAlimento] int  NOT NULL,
    [Grupo_IdGrupoAlimento] int  NOT NULL,
    [UnidadeMedidaPorcao_IdUnidadeMedida] int  NOT NULL
);
GO

-- Creating table 'ReferenciaAlimento'
CREATE TABLE [dbo].[ReferenciaAlimento] (
    [IdReferenciaAlimento] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'GrupoAlimento'
CREATE TABLE [dbo].[GrupoAlimento] (
    [IdGrupoAlimento] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Nutriente'
CREATE TABLE [dbo].[Nutriente] (
    [IdNutriente] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(100)  NOT NULL,
    [Simbolo] nvarchar(5)  NOT NULL,
    [Tipo_IdTipoNutriente] int  NOT NULL,
    [Categoria_IdCategoriaNutriente] int  NOT NULL
);
GO

-- Creating table 'TipoNutriente'
CREATE TABLE [dbo].[TipoNutriente] (
    [IdTipoNutriente] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(100)  NOT NULL
);
GO

-- Creating table 'CategoriaNutriente'
CREATE TABLE [dbo].[CategoriaNutriente] (
    [IdCategoriaNutriente] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Sexo'
CREATE TABLE [dbo].[Sexo] (
    [IdSexo] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'UnidadeMedida'
CREATE TABLE [dbo].[UnidadeMedida] (
    [IdUnidadeMedida] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(100)  NOT NULL,
    [Simbolo] nvarchar(10)  NOT NULL,
    [Composta] bit  NOT NULL
);
GO

-- Creating table 'FonteReferencia'
CREATE TABLE [dbo].[FonteReferencia] (
    [IdFonteReferencia] int IDENTITY(1,1) NOT NULL,
    [Tipo_IdTipoFonteReferencia] int  NOT NULL
);
GO

-- Creating table 'TabelaReferenciaNutriente'
CREATE TABLE [dbo].[TabelaReferenciaNutriente] (
    [IdTabelaReferenciaNutriente] int IDENTITY(1,1) NOT NULL,
    [Ano] smallint  NOT NULL,
    [Fonte_IdFonteReferencia] int  NOT NULL,
    [UnidadeMedida_IdUnidadeMedida] int  NOT NULL,
    [Nutriente_IdNutriente] int  NOT NULL
);
GO

-- Creating table 'ValorTabelaReferenciaNutriente'
CREATE TABLE [dbo].[ValorTabelaReferenciaNutriente] (
    [IdValorTabelaReferenciaNutriente] int IDENTITY(1,1) NOT NULL,
    [IdadeInicial] smallint  NOT NULL,
    [IdadeFinal] smallint  NOT NULL,
    [Valor1] decimal(9,3)  NOT NULL,
    [Valor2] decimal(9,3)  NULL,
    [TabelaReferencia_IdTabelaReferenciaNutriente] int  NOT NULL
);
GO

-- Creating table 'TipoFonteReferencia'
CREATE TABLE [dbo].[TipoFonteReferencia] (
    [IdTipoFonteReferencia] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'TabelaReferenciaAlimento'
CREATE TABLE [dbo].[TabelaReferenciaAlimento] (
    [IdTabelaReferenciaAlimento] int IDENTITY(1,1) NOT NULL,
    [TipoNutriente_IdTipoNutriente] int  NOT NULL,
    [Alimento_IdAlimento] int  NOT NULL
);
GO

-- Creating table 'ValorTabelaReferenciaAlimento'
CREATE TABLE [dbo].[ValorTabelaReferenciaAlimento] (
    [IdValorTabelaReferenciaAlimento] int IDENTITY(1,1) NOT NULL,
    [Valor] decimal(9,3)  NOT NULL,
    [UnidadeMedida_IdUnidadeMedida] int  NOT NULL,
    [Nutriente_IdNutriente] int  NOT NULL,
    [TabelaReferenciaAlimento_IdTabelaReferenciaAlimento] int  NOT NULL
);
GO

-- Creating table 'Exame'
CREATE TABLE [dbo].[Exame] (
    [IdExame] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(100)  NOT NULL,
    [ValorReferencia] decimal(9,3)  NULL,
    [UnidadeMedidaReferencia_IdUnidadeMedida] int  NOT NULL,
    [Tipo_IdTipoExame] int  NOT NULL
);
GO

-- Creating table 'TipoExame'
CREATE TABLE [dbo].[TipoExame] (
    [IdTipoExame] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(100)  NOT NULL
);
GO

-- Creating table 'Receita'
CREATE TABLE [dbo].[Receita] (
    [IdReceita] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(150)  NOT NULL,
    [Ingredientes] nvarchar(max)  NOT NULL,
    [ModoPreparo] nvarchar(max)  NOT NULL,
    [Rendimento] nvarchar(100)  NULL,
    [Acompanhamento] nvarchar(250)  NULL,
    [Imagem] varbinary(max)  NULL,
    [Categoria_IdCategoriaReceita] int  NOT NULL
);
GO

-- Creating table 'CategoriaReceita'
CREATE TABLE [dbo].[CategoriaReceita] (
    [IdCategoriaReceita] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(100)  NOT NULL
);
GO

-- Creating table 'Sintoma'
CREATE TABLE [dbo].[Sintoma] (
    [IdSintoma] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(100)  NOT NULL,
    [Descricao] nvarchar(max)  NOT NULL,
    [Imagem] varbinary(max)  NULL,
    [OrgaoHumano_IdOrgaoHumano] int  NOT NULL
);
GO

-- Creating table 'OrgaoHumano'
CREATE TABLE [dbo].[OrgaoHumano] (
    [IdOrgaoHumano] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Fitoterapico'
CREATE TABLE [dbo].[Fitoterapico] (
    [IdFitoterapico] int IDENTITY(1,1) NOT NULL,
    [NomenclaturaBotanica] nvarchar(100)  NOT NULL,
    [NomenclaturaPopular] nvarchar(100)  NULL,
    [ParteUtilizada] nvarchar(50)  NULL,
    [FormaUtilizacao] nvarchar(max)  NULL,
    [Posologia] nvarchar(200)  NULL,
    [Via] nvarchar(50)  NULL,
    [Uso] nvarchar(50)  NULL,
    [ContraIndicacoes] nvarchar(max)  NULL,
    [EfeitosAdversos] nvarchar(max)  NULL,
    [Observacoes] nvarchar(max)  NULL
);
GO

-- Creating table 'AtividadeFisica'
CREATE TABLE [dbo].[AtividadeFisica] (
    [IdAtividadeFisica] int IDENTITY(1,1) NOT NULL,
    [MET] decimal(9,3)  NOT NULL
);
GO

-- Creating table 'Consulta'
CREATE TABLE [dbo].[Consulta] (
    [IdConsulta] int IDENTITY(1,1) NOT NULL,
    [Data] datetime  NOT NULL,
    [Paciente_IdPaciente] int  NOT NULL
);
GO

-- Creating table 'Doenca'
CREATE TABLE [dbo].[Doenca] (
    [IdDoenca] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(100)  NOT NULL,
    [Tipo_IdTipoDoenca] int  NOT NULL
);
GO

-- Creating table 'TipoDoenca'
CREATE TABLE [dbo].[TipoDoenca] (
    [IdTipoDoenca] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'HistoriaSocioEconomica'
CREATE TABLE [dbo].[HistoriaSocioEconomica] (
    [IdHistoriaSocioEconomica] int IDENTITY(1,1) NOT NULL,
    [HoraInicioRotina] time  NULL,
    [HoraFimRotina] time  NULL,
    [PessoasResidencia] smallint  NULL,
    [ComQuemReside] nvarchar(max)  NULL,
    [DescricaoRotina] nvarchar(max)  NOT NULL,
    [HoraDormir] time  NULL,
    [HoraDespertar] time  NULL,
    [TemInsonia] bit  NOT NULL,
    [Lazer] nvarchar(max)  NULL,
    [Observacoes] nvarchar(max)  NULL,
    [Consulta_IdConsulta] int  NOT NULL,
    [Profissao_IdProfissao] int  NOT NULL,
    [MeioLocomocao_IdMeioLocomocao] int  NOT NULL,
    [FrequenciaTabaco_IdFrequenciaHabito] int  NOT NULL,
    [FrequenciaBebida_IdFrequenciaHabito] int  NOT NULL
);
GO

-- Creating table 'Profissao'
CREATE TABLE [dbo].[Profissao] (
    [IdProfissao] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(100)  NOT NULL
);
GO

-- Creating table 'MeioLocomocao'
CREATE TABLE [dbo].[MeioLocomocao] (
    [IdMeioLocomocao] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(100)  NOT NULL
);
GO

-- Creating table 'HistoriaSocioEconomicaAtividadeFisica'
CREATE TABLE [dbo].[HistoriaSocioEconomicaAtividadeFisica] (
    [IdHistoriaSocioEconomica] int  NOT NULL,
    [IdAtividadeFisica] int  NOT NULL,
    [HoraInicio] nvarchar(10)  NULL,
    [Duracao] smallint  NULL,
    [DiasSemana] tinyint  NOT NULL,
    [HistoriaSocioEconomica_IdHistoriaSocioEconomica] int  NOT NULL,
    [AtividadeFisica_IdAtividadeFisica] int  NOT NULL
);
GO

-- Creating table 'FrequenciaHabito'
CREATE TABLE [dbo].[FrequenciaHabito] (
    [IdFrequenciaHabito] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'HistoriaFamiliar'
CREATE TABLE [dbo].[HistoriaFamiliar] (
    [IdHistoriaFamiliar] int IDENTITY(1,1) NOT NULL,
    [Observacoes] nvarchar(max)  NULL,
    [Consulta_IdConsulta] int  NOT NULL
);
GO

-- Creating table 'SintomaNutrienteDeficiencia'
CREATE TABLE [dbo].[SintomaNutrienteDeficiencia] (
    [SintomaDeficiencia_IdSintoma] int  NOT NULL,
    [NutrientesDeficiencia_IdNutriente] int  NOT NULL
);
GO

-- Creating table 'SintomaNutrienteExcesso'
CREATE TABLE [dbo].[SintomaNutrienteExcesso] (
    [SintomaExcesso_IdSintoma] int  NOT NULL,
    [NutrienteExcesso_IdNutriente] int  NOT NULL
);
GO

-- Creating table 'DoencaExame'
CREATE TABLE [dbo].[DoencaExame] (
    [Doenca_IdDoenca] int  NOT NULL,
    [Exame_IdExame] int  NOT NULL
);
GO

-- Creating table 'HistoriaFamiliarDoenca'
CREATE TABLE [dbo].[HistoriaFamiliarDoenca] (
    [HistoriaFamiliar_IdHistoriaFamiliar] int  NOT NULL,
    [DoencasFamilia_IdDoenca] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [IdPaciente] in table 'Paciente'
ALTER TABLE [dbo].[Paciente]
ADD CONSTRAINT [PK_Paciente]
    PRIMARY KEY CLUSTERED ([IdPaciente] ASC);
GO

-- Creating primary key on [IdEstadoCivil] in table 'EstadoCivil'
ALTER TABLE [dbo].[EstadoCivil]
ADD CONSTRAINT [PK_EstadoCivil]
    PRIMARY KEY CLUSTERED ([IdEstadoCivil] ASC);
GO

-- Creating primary key on [IdGrupoEspecifico] in table 'GrupoEspecifico'
ALTER TABLE [dbo].[GrupoEspecifico]
ADD CONSTRAINT [PK_GrupoEspecifico]
    PRIMARY KEY CLUSTERED ([IdGrupoEspecifico] ASC);
GO

-- Creating primary key on [IdEtnia] in table 'Etnia'
ALTER TABLE [dbo].[Etnia]
ADD CONSTRAINT [PK_Etnia]
    PRIMARY KEY CLUSTERED ([IdEtnia] ASC);
GO

-- Creating primary key on [IdEndereco] in table 'Endereco'
ALTER TABLE [dbo].[Endereco]
ADD CONSTRAINT [PK_Endereco]
    PRIMARY KEY CLUSTERED ([IdEndereco] ASC);
GO

-- Creating primary key on [IdCidade] in table 'Cidade'
ALTER TABLE [dbo].[Cidade]
ADD CONSTRAINT [PK_Cidade]
    PRIMARY KEY CLUSTERED ([IdCidade] ASC);
GO

-- Creating primary key on [IdEstado] in table 'Estado'
ALTER TABLE [dbo].[Estado]
ADD CONSTRAINT [PK_Estado]
    PRIMARY KEY CLUSTERED ([IdEstado] ASC);
GO

-- Creating primary key on [IdPais] in table 'Pais'
ALTER TABLE [dbo].[Pais]
ADD CONSTRAINT [PK_Pais]
    PRIMARY KEY CLUSTERED ([IdPais] ASC);
GO

-- Creating primary key on [IdTipoEndereco] in table 'TipoEndereco'
ALTER TABLE [dbo].[TipoEndereco]
ADD CONSTRAINT [PK_TipoEndereco]
    PRIMARY KEY CLUSTERED ([IdTipoEndereco] ASC);
GO

-- Creating primary key on [IdAlimento] in table 'Alimento'
ALTER TABLE [dbo].[Alimento]
ADD CONSTRAINT [PK_Alimento]
    PRIMARY KEY CLUSTERED ([IdAlimento] ASC);
GO

-- Creating primary key on [IdReferenciaAlimento] in table 'ReferenciaAlimento'
ALTER TABLE [dbo].[ReferenciaAlimento]
ADD CONSTRAINT [PK_ReferenciaAlimento]
    PRIMARY KEY CLUSTERED ([IdReferenciaAlimento] ASC);
GO

-- Creating primary key on [IdGrupoAlimento] in table 'GrupoAlimento'
ALTER TABLE [dbo].[GrupoAlimento]
ADD CONSTRAINT [PK_GrupoAlimento]
    PRIMARY KEY CLUSTERED ([IdGrupoAlimento] ASC);
GO

-- Creating primary key on [IdNutriente] in table 'Nutriente'
ALTER TABLE [dbo].[Nutriente]
ADD CONSTRAINT [PK_Nutriente]
    PRIMARY KEY CLUSTERED ([IdNutriente] ASC);
GO

-- Creating primary key on [IdTipoNutriente] in table 'TipoNutriente'
ALTER TABLE [dbo].[TipoNutriente]
ADD CONSTRAINT [PK_TipoNutriente]
    PRIMARY KEY CLUSTERED ([IdTipoNutriente] ASC);
GO

-- Creating primary key on [IdCategoriaNutriente] in table 'CategoriaNutriente'
ALTER TABLE [dbo].[CategoriaNutriente]
ADD CONSTRAINT [PK_CategoriaNutriente]
    PRIMARY KEY CLUSTERED ([IdCategoriaNutriente] ASC);
GO

-- Creating primary key on [IdSexo] in table 'Sexo'
ALTER TABLE [dbo].[Sexo]
ADD CONSTRAINT [PK_Sexo]
    PRIMARY KEY CLUSTERED ([IdSexo] ASC);
GO

-- Creating primary key on [IdUnidadeMedida] in table 'UnidadeMedida'
ALTER TABLE [dbo].[UnidadeMedida]
ADD CONSTRAINT [PK_UnidadeMedida]
    PRIMARY KEY CLUSTERED ([IdUnidadeMedida] ASC);
GO

-- Creating primary key on [IdFonteReferencia] in table 'FonteReferencia'
ALTER TABLE [dbo].[FonteReferencia]
ADD CONSTRAINT [PK_FonteReferencia]
    PRIMARY KEY CLUSTERED ([IdFonteReferencia] ASC);
GO

-- Creating primary key on [IdTabelaReferenciaNutriente] in table 'TabelaReferenciaNutriente'
ALTER TABLE [dbo].[TabelaReferenciaNutriente]
ADD CONSTRAINT [PK_TabelaReferenciaNutriente]
    PRIMARY KEY CLUSTERED ([IdTabelaReferenciaNutriente] ASC);
GO

-- Creating primary key on [IdValorTabelaReferenciaNutriente] in table 'ValorTabelaReferenciaNutriente'
ALTER TABLE [dbo].[ValorTabelaReferenciaNutriente]
ADD CONSTRAINT [PK_ValorTabelaReferenciaNutriente]
    PRIMARY KEY CLUSTERED ([IdValorTabelaReferenciaNutriente] ASC);
GO

-- Creating primary key on [IdTipoFonteReferencia] in table 'TipoFonteReferencia'
ALTER TABLE [dbo].[TipoFonteReferencia]
ADD CONSTRAINT [PK_TipoFonteReferencia]
    PRIMARY KEY CLUSTERED ([IdTipoFonteReferencia] ASC);
GO

-- Creating primary key on [IdTabelaReferenciaAlimento] in table 'TabelaReferenciaAlimento'
ALTER TABLE [dbo].[TabelaReferenciaAlimento]
ADD CONSTRAINT [PK_TabelaReferenciaAlimento]
    PRIMARY KEY CLUSTERED ([IdTabelaReferenciaAlimento] ASC);
GO

-- Creating primary key on [IdValorTabelaReferenciaAlimento] in table 'ValorTabelaReferenciaAlimento'
ALTER TABLE [dbo].[ValorTabelaReferenciaAlimento]
ADD CONSTRAINT [PK_ValorTabelaReferenciaAlimento]
    PRIMARY KEY CLUSTERED ([IdValorTabelaReferenciaAlimento] ASC);
GO

-- Creating primary key on [IdExame] in table 'Exame'
ALTER TABLE [dbo].[Exame]
ADD CONSTRAINT [PK_Exame]
    PRIMARY KEY CLUSTERED ([IdExame] ASC);
GO

-- Creating primary key on [IdTipoExame] in table 'TipoExame'
ALTER TABLE [dbo].[TipoExame]
ADD CONSTRAINT [PK_TipoExame]
    PRIMARY KEY CLUSTERED ([IdTipoExame] ASC);
GO

-- Creating primary key on [IdReceita] in table 'Receita'
ALTER TABLE [dbo].[Receita]
ADD CONSTRAINT [PK_Receita]
    PRIMARY KEY CLUSTERED ([IdReceita] ASC);
GO

-- Creating primary key on [IdCategoriaReceita] in table 'CategoriaReceita'
ALTER TABLE [dbo].[CategoriaReceita]
ADD CONSTRAINT [PK_CategoriaReceita]
    PRIMARY KEY CLUSTERED ([IdCategoriaReceita] ASC);
GO

-- Creating primary key on [IdSintoma] in table 'Sintoma'
ALTER TABLE [dbo].[Sintoma]
ADD CONSTRAINT [PK_Sintoma]
    PRIMARY KEY CLUSTERED ([IdSintoma] ASC);
GO

-- Creating primary key on [IdOrgaoHumano] in table 'OrgaoHumano'
ALTER TABLE [dbo].[OrgaoHumano]
ADD CONSTRAINT [PK_OrgaoHumano]
    PRIMARY KEY CLUSTERED ([IdOrgaoHumano] ASC);
GO

-- Creating primary key on [IdFitoterapico] in table 'Fitoterapico'
ALTER TABLE [dbo].[Fitoterapico]
ADD CONSTRAINT [PK_Fitoterapico]
    PRIMARY KEY CLUSTERED ([IdFitoterapico] ASC);
GO

-- Creating primary key on [IdAtividadeFisica] in table 'AtividadeFisica'
ALTER TABLE [dbo].[AtividadeFisica]
ADD CONSTRAINT [PK_AtividadeFisica]
    PRIMARY KEY CLUSTERED ([IdAtividadeFisica] ASC);
GO

-- Creating primary key on [IdConsulta] in table 'Consulta'
ALTER TABLE [dbo].[Consulta]
ADD CONSTRAINT [PK_Consulta]
    PRIMARY KEY CLUSTERED ([IdConsulta] ASC);
GO

-- Creating primary key on [IdDoenca] in table 'Doenca'
ALTER TABLE [dbo].[Doenca]
ADD CONSTRAINT [PK_Doenca]
    PRIMARY KEY CLUSTERED ([IdDoenca] ASC);
GO

-- Creating primary key on [IdTipoDoenca] in table 'TipoDoenca'
ALTER TABLE [dbo].[TipoDoenca]
ADD CONSTRAINT [PK_TipoDoenca]
    PRIMARY KEY CLUSTERED ([IdTipoDoenca] ASC);
GO

-- Creating primary key on [IdHistoriaSocioEconomica] in table 'HistoriaSocioEconomica'
ALTER TABLE [dbo].[HistoriaSocioEconomica]
ADD CONSTRAINT [PK_HistoriaSocioEconomica]
    PRIMARY KEY CLUSTERED ([IdHistoriaSocioEconomica] ASC);
GO

-- Creating primary key on [IdProfissao] in table 'Profissao'
ALTER TABLE [dbo].[Profissao]
ADD CONSTRAINT [PK_Profissao]
    PRIMARY KEY CLUSTERED ([IdProfissao] ASC);
GO

-- Creating primary key on [IdMeioLocomocao] in table 'MeioLocomocao'
ALTER TABLE [dbo].[MeioLocomocao]
ADD CONSTRAINT [PK_MeioLocomocao]
    PRIMARY KEY CLUSTERED ([IdMeioLocomocao] ASC);
GO

-- Creating primary key on [IdHistoriaSocioEconomica], [IdAtividadeFisica] in table 'HistoriaSocioEconomicaAtividadeFisica'
ALTER TABLE [dbo].[HistoriaSocioEconomicaAtividadeFisica]
ADD CONSTRAINT [PK_HistoriaSocioEconomicaAtividadeFisica]
    PRIMARY KEY CLUSTERED ([IdHistoriaSocioEconomica], [IdAtividadeFisica] ASC);
GO

-- Creating primary key on [IdFrequenciaHabito] in table 'FrequenciaHabito'
ALTER TABLE [dbo].[FrequenciaHabito]
ADD CONSTRAINT [PK_FrequenciaHabito]
    PRIMARY KEY CLUSTERED ([IdFrequenciaHabito] ASC);
GO

-- Creating primary key on [IdHistoriaFamiliar] in table 'HistoriaFamiliar'
ALTER TABLE [dbo].[HistoriaFamiliar]
ADD CONSTRAINT [PK_HistoriaFamiliar]
    PRIMARY KEY CLUSTERED ([IdHistoriaFamiliar] ASC);
GO

-- Creating primary key on [SintomaDeficiencia_IdSintoma], [NutrientesDeficiencia_IdNutriente] in table 'SintomaNutrienteDeficiencia'
ALTER TABLE [dbo].[SintomaNutrienteDeficiencia]
ADD CONSTRAINT [PK_SintomaNutrienteDeficiencia]
    PRIMARY KEY NONCLUSTERED ([SintomaDeficiencia_IdSintoma], [NutrientesDeficiencia_IdNutriente] ASC);
GO

-- Creating primary key on [SintomaExcesso_IdSintoma], [NutrienteExcesso_IdNutriente] in table 'SintomaNutrienteExcesso'
ALTER TABLE [dbo].[SintomaNutrienteExcesso]
ADD CONSTRAINT [PK_SintomaNutrienteExcesso]
    PRIMARY KEY NONCLUSTERED ([SintomaExcesso_IdSintoma], [NutrienteExcesso_IdNutriente] ASC);
GO

-- Creating primary key on [Doenca_IdDoenca], [Exame_IdExame] in table 'DoencaExame'
ALTER TABLE [dbo].[DoencaExame]
ADD CONSTRAINT [PK_DoencaExame]
    PRIMARY KEY NONCLUSTERED ([Doenca_IdDoenca], [Exame_IdExame] ASC);
GO

-- Creating primary key on [HistoriaFamiliar_IdHistoriaFamiliar], [DoencasFamilia_IdDoenca] in table 'HistoriaFamiliarDoenca'
ALTER TABLE [dbo].[HistoriaFamiliarDoenca]
ADD CONSTRAINT [PK_HistoriaFamiliarDoenca]
    PRIMARY KEY NONCLUSTERED ([HistoriaFamiliar_IdHistoriaFamiliar], [DoencasFamilia_IdDoenca] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [EstadoCivil_IdEstadoCivil] in table 'Paciente'
ALTER TABLE [dbo].[Paciente]
ADD CONSTRAINT [FK_EstadoCivilPaciente]
    FOREIGN KEY ([EstadoCivil_IdEstadoCivil])
    REFERENCES [dbo].[EstadoCivil]
        ([IdEstadoCivil])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EstadoCivilPaciente'
CREATE INDEX [IX_FK_EstadoCivilPaciente]
ON [dbo].[Paciente]
    ([EstadoCivil_IdEstadoCivil]);
GO

-- Creating foreign key on [GrupoEspecifico_IdGrupoEspecifico] in table 'Paciente'
ALTER TABLE [dbo].[Paciente]
ADD CONSTRAINT [FK_GrupoEspecificoPaciente]
    FOREIGN KEY ([GrupoEspecifico_IdGrupoEspecifico])
    REFERENCES [dbo].[GrupoEspecifico]
        ([IdGrupoEspecifico])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GrupoEspecificoPaciente'
CREATE INDEX [IX_FK_GrupoEspecificoPaciente]
ON [dbo].[Paciente]
    ([GrupoEspecifico_IdGrupoEspecifico]);
GO

-- Creating foreign key on [Etnia_IdEtnia] in table 'Paciente'
ALTER TABLE [dbo].[Paciente]
ADD CONSTRAINT [FK_EtniaPaciente]
    FOREIGN KEY ([Etnia_IdEtnia])
    REFERENCES [dbo].[Etnia]
        ([IdEtnia])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EtniaPaciente'
CREATE INDEX [IX_FK_EtniaPaciente]
ON [dbo].[Paciente]
    ([Etnia_IdEtnia]);
GO

-- Creating foreign key on [Estado_IdEstado] in table 'Cidade'
ALTER TABLE [dbo].[Cidade]
ADD CONSTRAINT [FK_EstadoCidade]
    FOREIGN KEY ([Estado_IdEstado])
    REFERENCES [dbo].[Estado]
        ([IdEstado])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EstadoCidade'
CREATE INDEX [IX_FK_EstadoCidade]
ON [dbo].[Cidade]
    ([Estado_IdEstado]);
GO

-- Creating foreign key on [Pais_IdPais] in table 'Estado'
ALTER TABLE [dbo].[Estado]
ADD CONSTRAINT [FK_PaisEstado]
    FOREIGN KEY ([Pais_IdPais])
    REFERENCES [dbo].[Pais]
        ([IdPais])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PaisEstado'
CREATE INDEX [IX_FK_PaisEstado]
ON [dbo].[Estado]
    ([Pais_IdPais]);
GO

-- Creating foreign key on [Cidade_IdCidade] in table 'Endereco'
ALTER TABLE [dbo].[Endereco]
ADD CONSTRAINT [FK_CidadeEndereco]
    FOREIGN KEY ([Cidade_IdCidade])
    REFERENCES [dbo].[Cidade]
        ([IdCidade])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CidadeEndereco'
CREATE INDEX [IX_FK_CidadeEndereco]
ON [dbo].[Endereco]
    ([Cidade_IdCidade]);
GO

-- Creating foreign key on [Tipo_IdTipoEndereco] in table 'Endereco'
ALTER TABLE [dbo].[Endereco]
ADD CONSTRAINT [FK_TipoEnderecoEndereco]
    FOREIGN KEY ([Tipo_IdTipoEndereco])
    REFERENCES [dbo].[TipoEndereco]
        ([IdTipoEndereco])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TipoEnderecoEndereco'
CREATE INDEX [IX_FK_TipoEnderecoEndereco]
ON [dbo].[Endereco]
    ([Tipo_IdTipoEndereco]);
GO

-- Creating foreign key on [Paciente_IdPaciente] in table 'Endereco'
ALTER TABLE [dbo].[Endereco]
ADD CONSTRAINT [FK_PacienteEndereco]
    FOREIGN KEY ([Paciente_IdPaciente])
    REFERENCES [dbo].[Paciente]
        ([IdPaciente])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PacienteEndereco'
CREATE INDEX [IX_FK_PacienteEndereco]
ON [dbo].[Endereco]
    ([Paciente_IdPaciente]);
GO

-- Creating foreign key on [Referencia_IdReferenciaAlimento] in table 'Alimento'
ALTER TABLE [dbo].[Alimento]
ADD CONSTRAINT [FK_ReferenciaAlimentoAlimento]
    FOREIGN KEY ([Referencia_IdReferenciaAlimento])
    REFERENCES [dbo].[ReferenciaAlimento]
        ([IdReferenciaAlimento])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ReferenciaAlimentoAlimento'
CREATE INDEX [IX_FK_ReferenciaAlimentoAlimento]
ON [dbo].[Alimento]
    ([Referencia_IdReferenciaAlimento]);
GO

-- Creating foreign key on [Grupo_IdGrupoAlimento] in table 'Alimento'
ALTER TABLE [dbo].[Alimento]
ADD CONSTRAINT [FK_GrupoAlimentoAlimento]
    FOREIGN KEY ([Grupo_IdGrupoAlimento])
    REFERENCES [dbo].[GrupoAlimento]
        ([IdGrupoAlimento])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GrupoAlimentoAlimento'
CREATE INDEX [IX_FK_GrupoAlimentoAlimento]
ON [dbo].[Alimento]
    ([Grupo_IdGrupoAlimento]);
GO

-- Creating foreign key on [Tipo_IdTipoNutriente] in table 'Nutriente'
ALTER TABLE [dbo].[Nutriente]
ADD CONSTRAINT [FK_TipoNutrienteNutriente]
    FOREIGN KEY ([Tipo_IdTipoNutriente])
    REFERENCES [dbo].[TipoNutriente]
        ([IdTipoNutriente])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TipoNutrienteNutriente'
CREATE INDEX [IX_FK_TipoNutrienteNutriente]
ON [dbo].[Nutriente]
    ([Tipo_IdTipoNutriente]);
GO

-- Creating foreign key on [Categoria_IdCategoriaNutriente] in table 'Nutriente'
ALTER TABLE [dbo].[Nutriente]
ADD CONSTRAINT [FK_CategoriaNutrienteNutriente]
    FOREIGN KEY ([Categoria_IdCategoriaNutriente])
    REFERENCES [dbo].[CategoriaNutriente]
        ([IdCategoriaNutriente])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoriaNutrienteNutriente'
CREATE INDEX [IX_FK_CategoriaNutrienteNutriente]
ON [dbo].[Nutriente]
    ([Categoria_IdCategoriaNutriente]);
GO

-- Creating foreign key on [Sexo_IdSexo] in table 'Paciente'
ALTER TABLE [dbo].[Paciente]
ADD CONSTRAINT [FK_SexoPaciente]
    FOREIGN KEY ([Sexo_IdSexo])
    REFERENCES [dbo].[Sexo]
        ([IdSexo])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SexoPaciente'
CREATE INDEX [IX_FK_SexoPaciente]
ON [dbo].[Paciente]
    ([Sexo_IdSexo]);
GO

-- Creating foreign key on [Fonte_IdFonteReferencia] in table 'TabelaReferenciaNutriente'
ALTER TABLE [dbo].[TabelaReferenciaNutriente]
ADD CONSTRAINT [FK_FonteReferenciaTabelaReferencia]
    FOREIGN KEY ([Fonte_IdFonteReferencia])
    REFERENCES [dbo].[FonteReferencia]
        ([IdFonteReferencia])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FonteReferenciaTabelaReferencia'
CREATE INDEX [IX_FK_FonteReferenciaTabelaReferencia]
ON [dbo].[TabelaReferenciaNutriente]
    ([Fonte_IdFonteReferencia]);
GO

-- Creating foreign key on [UnidadeMedida_IdUnidadeMedida] in table 'TabelaReferenciaNutriente'
ALTER TABLE [dbo].[TabelaReferenciaNutriente]
ADD CONSTRAINT [FK_UnidadeMedidaTabelaReferencia]
    FOREIGN KEY ([UnidadeMedida_IdUnidadeMedida])
    REFERENCES [dbo].[UnidadeMedida]
        ([IdUnidadeMedida])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UnidadeMedidaTabelaReferencia'
CREATE INDEX [IX_FK_UnidadeMedidaTabelaReferencia]
ON [dbo].[TabelaReferenciaNutriente]
    ([UnidadeMedida_IdUnidadeMedida]);
GO

-- Creating foreign key on [TabelaReferencia_IdTabelaReferenciaNutriente] in table 'ValorTabelaReferenciaNutriente'
ALTER TABLE [dbo].[ValorTabelaReferenciaNutriente]
ADD CONSTRAINT [FK_TabelaReferenciaValorTabelaReferencia]
    FOREIGN KEY ([TabelaReferencia_IdTabelaReferenciaNutriente])
    REFERENCES [dbo].[TabelaReferenciaNutriente]
        ([IdTabelaReferenciaNutriente])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TabelaReferenciaValorTabelaReferencia'
CREATE INDEX [IX_FK_TabelaReferenciaValorTabelaReferencia]
ON [dbo].[ValorTabelaReferenciaNutriente]
    ([TabelaReferencia_IdTabelaReferenciaNutriente]);
GO

-- Creating foreign key on [Nutriente_IdNutriente] in table 'TabelaReferenciaNutriente'
ALTER TABLE [dbo].[TabelaReferenciaNutriente]
ADD CONSTRAINT [FK_NutrienteTabelaReferencia]
    FOREIGN KEY ([Nutriente_IdNutriente])
    REFERENCES [dbo].[Nutriente]
        ([IdNutriente])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NutrienteTabelaReferencia'
CREATE INDEX [IX_FK_NutrienteTabelaReferencia]
ON [dbo].[TabelaReferenciaNutriente]
    ([Nutriente_IdNutriente]);
GO

-- Creating foreign key on [Tipo_IdTipoFonteReferencia] in table 'FonteReferencia'
ALTER TABLE [dbo].[FonteReferencia]
ADD CONSTRAINT [FK_TipoFonteReferenciaFonteReferencia]
    FOREIGN KEY ([Tipo_IdTipoFonteReferencia])
    REFERENCES [dbo].[TipoFonteReferencia]
        ([IdTipoFonteReferencia])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TipoFonteReferenciaFonteReferencia'
CREATE INDEX [IX_FK_TipoFonteReferenciaFonteReferencia]
ON [dbo].[FonteReferencia]
    ([Tipo_IdTipoFonteReferencia]);
GO

-- Creating foreign key on [TipoNutriente_IdTipoNutriente] in table 'TabelaReferenciaAlimento'
ALTER TABLE [dbo].[TabelaReferenciaAlimento]
ADD CONSTRAINT [FK_TipoNutrienteTabelaReferenciaAlimento]
    FOREIGN KEY ([TipoNutriente_IdTipoNutriente])
    REFERENCES [dbo].[TipoNutriente]
        ([IdTipoNutriente])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TipoNutrienteTabelaReferenciaAlimento'
CREATE INDEX [IX_FK_TipoNutrienteTabelaReferenciaAlimento]
ON [dbo].[TabelaReferenciaAlimento]
    ([TipoNutriente_IdTipoNutriente]);
GO

-- Creating foreign key on [UnidadeMedida_IdUnidadeMedida] in table 'ValorTabelaReferenciaAlimento'
ALTER TABLE [dbo].[ValorTabelaReferenciaAlimento]
ADD CONSTRAINT [FK_UnidadeMedidaValorTabelaReferenciaAlimento]
    FOREIGN KEY ([UnidadeMedida_IdUnidadeMedida])
    REFERENCES [dbo].[UnidadeMedida]
        ([IdUnidadeMedida])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UnidadeMedidaValorTabelaReferenciaAlimento'
CREATE INDEX [IX_FK_UnidadeMedidaValorTabelaReferenciaAlimento]
ON [dbo].[ValorTabelaReferenciaAlimento]
    ([UnidadeMedida_IdUnidadeMedida]);
GO

-- Creating foreign key on [Nutriente_IdNutriente] in table 'ValorTabelaReferenciaAlimento'
ALTER TABLE [dbo].[ValorTabelaReferenciaAlimento]
ADD CONSTRAINT [FK_NutrienteValorTabelaReferenciaAlimento]
    FOREIGN KEY ([Nutriente_IdNutriente])
    REFERENCES [dbo].[Nutriente]
        ([IdNutriente])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NutrienteValorTabelaReferenciaAlimento'
CREATE INDEX [IX_FK_NutrienteValorTabelaReferenciaAlimento]
ON [dbo].[ValorTabelaReferenciaAlimento]
    ([Nutriente_IdNutriente]);
GO

-- Creating foreign key on [UnidadeMedidaPorcao_IdUnidadeMedida] in table 'Alimento'
ALTER TABLE [dbo].[Alimento]
ADD CONSTRAINT [FK_UnidadeMedidaAlimento]
    FOREIGN KEY ([UnidadeMedidaPorcao_IdUnidadeMedida])
    REFERENCES [dbo].[UnidadeMedida]
        ([IdUnidadeMedida])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UnidadeMedidaAlimento'
CREATE INDEX [IX_FK_UnidadeMedidaAlimento]
ON [dbo].[Alimento]
    ([UnidadeMedidaPorcao_IdUnidadeMedida]);
GO

-- Creating foreign key on [UnidadeMedidaReferencia_IdUnidadeMedida] in table 'Exame'
ALTER TABLE [dbo].[Exame]
ADD CONSTRAINT [FK_UnidadeMedidaExame]
    FOREIGN KEY ([UnidadeMedidaReferencia_IdUnidadeMedida])
    REFERENCES [dbo].[UnidadeMedida]
        ([IdUnidadeMedida])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UnidadeMedidaExame'
CREATE INDEX [IX_FK_UnidadeMedidaExame]
ON [dbo].[Exame]
    ([UnidadeMedidaReferencia_IdUnidadeMedida]);
GO

-- Creating foreign key on [Tipo_IdTipoExame] in table 'Exame'
ALTER TABLE [dbo].[Exame]
ADD CONSTRAINT [FK_TipoExameExame]
    FOREIGN KEY ([Tipo_IdTipoExame])
    REFERENCES [dbo].[TipoExame]
        ([IdTipoExame])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TipoExameExame'
CREATE INDEX [IX_FK_TipoExameExame]
ON [dbo].[Exame]
    ([Tipo_IdTipoExame]);
GO

-- Creating foreign key on [Alimento_IdAlimento] in table 'TabelaReferenciaAlimento'
ALTER TABLE [dbo].[TabelaReferenciaAlimento]
ADD CONSTRAINT [FK_AlimentoTabelaReferenciaAlimento]
    FOREIGN KEY ([Alimento_IdAlimento])
    REFERENCES [dbo].[Alimento]
        ([IdAlimento])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AlimentoTabelaReferenciaAlimento'
CREATE INDEX [IX_FK_AlimentoTabelaReferenciaAlimento]
ON [dbo].[TabelaReferenciaAlimento]
    ([Alimento_IdAlimento]);
GO

-- Creating foreign key on [TabelaReferenciaAlimento_IdTabelaReferenciaAlimento] in table 'ValorTabelaReferenciaAlimento'
ALTER TABLE [dbo].[ValorTabelaReferenciaAlimento]
ADD CONSTRAINT [FK_TabelaReferenciaAlimentoValorTabelaReferenciaAlimento]
    FOREIGN KEY ([TabelaReferenciaAlimento_IdTabelaReferenciaAlimento])
    REFERENCES [dbo].[TabelaReferenciaAlimento]
        ([IdTabelaReferenciaAlimento])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TabelaReferenciaAlimentoValorTabelaReferenciaAlimento'
CREATE INDEX [IX_FK_TabelaReferenciaAlimentoValorTabelaReferenciaAlimento]
ON [dbo].[ValorTabelaReferenciaAlimento]
    ([TabelaReferenciaAlimento_IdTabelaReferenciaAlimento]);
GO

-- Creating foreign key on [Categoria_IdCategoriaReceita] in table 'Receita'
ALTER TABLE [dbo].[Receita]
ADD CONSTRAINT [FK_CategoriaReceitaReceita]
    FOREIGN KEY ([Categoria_IdCategoriaReceita])
    REFERENCES [dbo].[CategoriaReceita]
        ([IdCategoriaReceita])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoriaReceitaReceita'
CREATE INDEX [IX_FK_CategoriaReceitaReceita]
ON [dbo].[Receita]
    ([Categoria_IdCategoriaReceita]);
GO

-- Creating foreign key on [OrgaoHumano_IdOrgaoHumano] in table 'Sintoma'
ALTER TABLE [dbo].[Sintoma]
ADD CONSTRAINT [FK_OrgaoHumanoSintoma]
    FOREIGN KEY ([OrgaoHumano_IdOrgaoHumano])
    REFERENCES [dbo].[OrgaoHumano]
        ([IdOrgaoHumano])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrgaoHumanoSintoma'
CREATE INDEX [IX_FK_OrgaoHumanoSintoma]
ON [dbo].[Sintoma]
    ([OrgaoHumano_IdOrgaoHumano]);
GO

-- Creating foreign key on [SintomaDeficiencia_IdSintoma] in table 'SintomaNutrienteDeficiencia'
ALTER TABLE [dbo].[SintomaNutrienteDeficiencia]
ADD CONSTRAINT [FK_SintomaNutrienteDeficiencia_Sintoma]
    FOREIGN KEY ([SintomaDeficiencia_IdSintoma])
    REFERENCES [dbo].[Sintoma]
        ([IdSintoma])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [NutrientesDeficiencia_IdNutriente] in table 'SintomaNutrienteDeficiencia'
ALTER TABLE [dbo].[SintomaNutrienteDeficiencia]
ADD CONSTRAINT [FK_SintomaNutrienteDeficiencia_Nutriente]
    FOREIGN KEY ([NutrientesDeficiencia_IdNutriente])
    REFERENCES [dbo].[Nutriente]
        ([IdNutriente])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SintomaNutrienteDeficiencia_Nutriente'
CREATE INDEX [IX_FK_SintomaNutrienteDeficiencia_Nutriente]
ON [dbo].[SintomaNutrienteDeficiencia]
    ([NutrientesDeficiencia_IdNutriente]);
GO

-- Creating foreign key on [SintomaExcesso_IdSintoma] in table 'SintomaNutrienteExcesso'
ALTER TABLE [dbo].[SintomaNutrienteExcesso]
ADD CONSTRAINT [FK_SintomaNutrienteExcesso_Sintoma]
    FOREIGN KEY ([SintomaExcesso_IdSintoma])
    REFERENCES [dbo].[Sintoma]
        ([IdSintoma])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [NutrienteExcesso_IdNutriente] in table 'SintomaNutrienteExcesso'
ALTER TABLE [dbo].[SintomaNutrienteExcesso]
ADD CONSTRAINT [FK_SintomaNutrienteExcesso_Nutriente]
    FOREIGN KEY ([NutrienteExcesso_IdNutriente])
    REFERENCES [dbo].[Nutriente]
        ([IdNutriente])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SintomaNutrienteExcesso_Nutriente'
CREATE INDEX [IX_FK_SintomaNutrienteExcesso_Nutriente]
ON [dbo].[SintomaNutrienteExcesso]
    ([NutrienteExcesso_IdNutriente]);
GO

-- Creating foreign key on [Paciente_IdPaciente] in table 'Consulta'
ALTER TABLE [dbo].[Consulta]
ADD CONSTRAINT [FK_PacienteConsulta]
    FOREIGN KEY ([Paciente_IdPaciente])
    REFERENCES [dbo].[Paciente]
        ([IdPaciente])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PacienteConsulta'
CREATE INDEX [IX_FK_PacienteConsulta]
ON [dbo].[Consulta]
    ([Paciente_IdPaciente]);
GO

-- Creating foreign key on [Tipo_IdTipoDoenca] in table 'Doenca'
ALTER TABLE [dbo].[Doenca]
ADD CONSTRAINT [FK_TipoDoencaDoenca]
    FOREIGN KEY ([Tipo_IdTipoDoenca])
    REFERENCES [dbo].[TipoDoenca]
        ([IdTipoDoenca])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TipoDoencaDoenca'
CREATE INDEX [IX_FK_TipoDoencaDoenca]
ON [dbo].[Doenca]
    ([Tipo_IdTipoDoenca]);
GO

-- Creating foreign key on [Doenca_IdDoenca] in table 'DoencaExame'
ALTER TABLE [dbo].[DoencaExame]
ADD CONSTRAINT [FK_DoencaExame_Doenca]
    FOREIGN KEY ([Doenca_IdDoenca])
    REFERENCES [dbo].[Doenca]
        ([IdDoenca])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Exame_IdExame] in table 'DoencaExame'
ALTER TABLE [dbo].[DoencaExame]
ADD CONSTRAINT [FK_DoencaExame_Exame]
    FOREIGN KEY ([Exame_IdExame])
    REFERENCES [dbo].[Exame]
        ([IdExame])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DoencaExame_Exame'
CREATE INDEX [IX_FK_DoencaExame_Exame]
ON [dbo].[DoencaExame]
    ([Exame_IdExame]);
GO

-- Creating foreign key on [Consulta_IdConsulta] in table 'HistoriaSocioEconomica'
ALTER TABLE [dbo].[HistoriaSocioEconomica]
ADD CONSTRAINT [FK_ConsultaHistoriaSocioEconomica]
    FOREIGN KEY ([Consulta_IdConsulta])
    REFERENCES [dbo].[Consulta]
        ([IdConsulta])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ConsultaHistoriaSocioEconomica'
CREATE INDEX [IX_FK_ConsultaHistoriaSocioEconomica]
ON [dbo].[HistoriaSocioEconomica]
    ([Consulta_IdConsulta]);
GO

-- Creating foreign key on [Profissao_IdProfissao] in table 'HistoriaSocioEconomica'
ALTER TABLE [dbo].[HistoriaSocioEconomica]
ADD CONSTRAINT [FK_ProfissaoHistoriaSocioEconomica]
    FOREIGN KEY ([Profissao_IdProfissao])
    REFERENCES [dbo].[Profissao]
        ([IdProfissao])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProfissaoHistoriaSocioEconomica'
CREATE INDEX [IX_FK_ProfissaoHistoriaSocioEconomica]
ON [dbo].[HistoriaSocioEconomica]
    ([Profissao_IdProfissao]);
GO

-- Creating foreign key on [MeioLocomocao_IdMeioLocomocao] in table 'HistoriaSocioEconomica'
ALTER TABLE [dbo].[HistoriaSocioEconomica]
ADD CONSTRAINT [FK_MeioLocomocaoHistoriaSocioEconomica]
    FOREIGN KEY ([MeioLocomocao_IdMeioLocomocao])
    REFERENCES [dbo].[MeioLocomocao]
        ([IdMeioLocomocao])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MeioLocomocaoHistoriaSocioEconomica'
CREATE INDEX [IX_FK_MeioLocomocaoHistoriaSocioEconomica]
ON [dbo].[HistoriaSocioEconomica]
    ([MeioLocomocao_IdMeioLocomocao]);
GO

-- Creating foreign key on [HistoriaSocioEconomica_IdHistoriaSocioEconomica] in table 'HistoriaSocioEconomicaAtividadeFisica'
ALTER TABLE [dbo].[HistoriaSocioEconomicaAtividadeFisica]
ADD CONSTRAINT [FK_HistoriaSocioEconomicaHistoriaSocioEconomicaAtividadeFisica]
    FOREIGN KEY ([HistoriaSocioEconomica_IdHistoriaSocioEconomica])
    REFERENCES [dbo].[HistoriaSocioEconomica]
        ([IdHistoriaSocioEconomica])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HistoriaSocioEconomicaHistoriaSocioEconomicaAtividadeFisica'
CREATE INDEX [IX_FK_HistoriaSocioEconomicaHistoriaSocioEconomicaAtividadeFisica]
ON [dbo].[HistoriaSocioEconomicaAtividadeFisica]
    ([HistoriaSocioEconomica_IdHistoriaSocioEconomica]);
GO

-- Creating foreign key on [AtividadeFisica_IdAtividadeFisica] in table 'HistoriaSocioEconomicaAtividadeFisica'
ALTER TABLE [dbo].[HistoriaSocioEconomicaAtividadeFisica]
ADD CONSTRAINT [FK_AtividadeFisicaHistoriaSocioEconomicaAtividadeFisica]
    FOREIGN KEY ([AtividadeFisica_IdAtividadeFisica])
    REFERENCES [dbo].[AtividadeFisica]
        ([IdAtividadeFisica])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AtividadeFisicaHistoriaSocioEconomicaAtividadeFisica'
CREATE INDEX [IX_FK_AtividadeFisicaHistoriaSocioEconomicaAtividadeFisica]
ON [dbo].[HistoriaSocioEconomicaAtividadeFisica]
    ([AtividadeFisica_IdAtividadeFisica]);
GO

-- Creating foreign key on [FrequenciaTabaco_IdFrequenciaHabito] in table 'HistoriaSocioEconomica'
ALTER TABLE [dbo].[HistoriaSocioEconomica]
ADD CONSTRAINT [FK_FrequenciaHabitoTabacoHistoriaSocioEconomica]
    FOREIGN KEY ([FrequenciaTabaco_IdFrequenciaHabito])
    REFERENCES [dbo].[FrequenciaHabito]
        ([IdFrequenciaHabito])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FrequenciaHabitoTabacoHistoriaSocioEconomica'
CREATE INDEX [IX_FK_FrequenciaHabitoTabacoHistoriaSocioEconomica]
ON [dbo].[HistoriaSocioEconomica]
    ([FrequenciaTabaco_IdFrequenciaHabito]);
GO

-- Creating foreign key on [FrequenciaBebida_IdFrequenciaHabito] in table 'HistoriaSocioEconomica'
ALTER TABLE [dbo].[HistoriaSocioEconomica]
ADD CONSTRAINT [FK_FrequenciaHabitoBebidaHistoriaSocioEconomica]
    FOREIGN KEY ([FrequenciaBebida_IdFrequenciaHabito])
    REFERENCES [dbo].[FrequenciaHabito]
        ([IdFrequenciaHabito])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FrequenciaHabitoBebidaHistoriaSocioEconomica'
CREATE INDEX [IX_FK_FrequenciaHabitoBebidaHistoriaSocioEconomica]
ON [dbo].[HistoriaSocioEconomica]
    ([FrequenciaBebida_IdFrequenciaHabito]);
GO

-- Creating foreign key on [Consulta_IdConsulta] in table 'HistoriaFamiliar'
ALTER TABLE [dbo].[HistoriaFamiliar]
ADD CONSTRAINT [FK_ConsultaHistoriaFamiliar]
    FOREIGN KEY ([Consulta_IdConsulta])
    REFERENCES [dbo].[Consulta]
        ([IdConsulta])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ConsultaHistoriaFamiliar'
CREATE INDEX [IX_FK_ConsultaHistoriaFamiliar]
ON [dbo].[HistoriaFamiliar]
    ([Consulta_IdConsulta]);
GO

-- Creating foreign key on [HistoriaFamiliar_IdHistoriaFamiliar] in table 'HistoriaFamiliarDoenca'
ALTER TABLE [dbo].[HistoriaFamiliarDoenca]
ADD CONSTRAINT [FK_HistoriaFamiliarDoenca_HistoriaFamiliar]
    FOREIGN KEY ([HistoriaFamiliar_IdHistoriaFamiliar])
    REFERENCES [dbo].[HistoriaFamiliar]
        ([IdHistoriaFamiliar])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [DoencasFamilia_IdDoenca] in table 'HistoriaFamiliarDoenca'
ALTER TABLE [dbo].[HistoriaFamiliarDoenca]
ADD CONSTRAINT [FK_HistoriaFamiliarDoenca_Doenca]
    FOREIGN KEY ([DoencasFamilia_IdDoenca])
    REFERENCES [dbo].[Doenca]
        ([IdDoenca])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HistoriaFamiliarDoenca_Doenca'
CREATE INDEX [IX_FK_HistoriaFamiliarDoenca_Doenca]
ON [dbo].[HistoriaFamiliarDoenca]
    ([DoencasFamilia_IdDoenca]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------